<template>
  <div class="wrapper">
    <!-- v-if 解决轮播图在页面加载完成之后，显示的是最后一张图片的问题 -->
    <swiper :options="swiperOption" v-if="list.length">
      <swiper-slide v-for="item of list" :key="item.id">
        <img class="swiper-img" :src="item.imgUrl" />
      </swiper-slide>
      <!-- Optional controls -->
      <div class="swiper-pagination"  slot="pagination"></div>
      <!-- <div class="swiper-button-prev" slot="button-prev"></div>
      <div class="swiper-button-next" slot="button-next"></div>
      <div class="swiper-scrollbar"   slot="scrollbar"></div> -->
    </swiper>
  </div>
</template>

<script>
export default {
  name: 'homeSwiper',
  props: {
    list: Array
  },
  data () {
    return {
      swiperOption: {
        pagination: '.swiper-pagination',
        // 设置循环轮播
        loop: true
      }
    }
  }
}
</script>

<style scoped>
  /* 样式穿透，不受 scoped 的限制 */
  /* 设置当前图片的小圆点为白色 */
  .wrapper >>> .swiper-pagination-bullet-active {
    background: #fff
  }
  .wrapper {
    overflow: hidden;
    width: 100%;
    height: 0;
    padding-bottom: 31.25%;
  }
  .swiper-img {
    /* 图片宽高自适应？ */
    width: 100%;
  }
</style>
